<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>复选框反选</title>
</head>
<body>
<table border="1" align="center" width="300px">
    <tr>
        <td><input type="checkbox" onclick="f(this)"></td>
        <td align="center">用户名</td>
        <td align="center">密码</td>
    </tr>
    <tr>
        <td><input type="checkbox" name="1"></td>
        <td align="center">张三</td>
        <td align="center">333</td>
    </tr>
    <tr>
        <td><input type="checkbox" name="1"></td>
        <td align="center">李四</td>
        <td align="center">444</td>
    </tr>
    <tr>
        <td><input type="checkbox" name="1"></td>
        <td align="center">王五</td>
        <td align="center">555</td>
    </tr>
    <tr>
      <td>
          <a href="javaScript:fun();">反选</a>
      </td>
    </tr>

</table>
</body>

<script>
    function fun(){
        document.getElementsByName("1");
        for (let b = 0; b < cks.length; b++) {
            cks[b].checked=!cks[b].checked;
        }
    }


    //function事件
    function f(ck) {
        //alert(ck.checked)

        //获取要操作的的复选框对象
        let cks = document.getElementsByName("1");
        // alert(cks.length);
        //遍历
        for (let i=0;i<cks.length;i++){
            //全选全不选
            cks[i].checked=ck.checked;
        }
    }

</script>
</html>